﻿@* Generator: Template TypeVisibility: Internal GeneratePrettyNames: True *@
@using System
@using Hangfire.Dashboard
@using Hangfire.Dashboard.Pages
@using Hangfire.Dashboard.Resources
@inherits RazorPage
@{
    Layout = new LayoutPage(Strings.FailedJobsPage_Title);

    int from, perPage;

    int.TryParse(Query("from"), out from);
    int.TryParse(Query("count"), out perPage);

    var monitor = Storage.GetMonitoringApi();
    var pager = new Pager(from, perPage, monitor.FailedCount());
    var failedJobs = monitor.FailedJobs(pager.FromRecord, pager.RecordsPerPage);
}

<div class="row">
    <div class="col-md-3">
        @Html.JobsSidebar()
    </div>
    <div class="col-md-9">
        <h1 class="page-header">@Strings.FailedJobsPage_Title</h1>

        @if (pager.TotalPageCount == 0)
        {
            <div class="alert alert-success">
               @Strings.FailedJobsPage_NoJobs
            </div>
        }
        else
        {
            <div class="alert alert-warning">
                @Html.Raw(Strings.FailedJobsPage_FailedJobsNotExpire_Warning_Html)
            </div>
            
            <div class="js-jobs-list">
                <div class="btn-toolbar btn-toolbar-top">
                    <button class="js-jobs-list-command btn btn-sm btn-primary"
                            data-url="@Url.To("/jobs/failed/requeue")"
                            data-loading-text="@Strings.Common_Enqueueing"
                            disabled="disabled">
                        <span class="glyphicon glyphicon-repeat"></span>
                        @Strings.Common_RequeueJobs
                    </button>

                    <button class="js-jobs-list-command btn btn-sm btn-default"
                            data-url="@Url.To("/jobs/failed/delete")"
                            data-loading-text="@Strings.Common_Deleting"
                            data-confirm="@Strings.Common_DeleteConfirm">
                        <span class="glyphicon glyphicon-remove"></span>
                        @Strings.Common_DeleteSelected
                    </button>

                    @Html.PerPageSelector(pager)
                </div>

                <div class="table-responsive">
                    <table class="table">
                        <thead>
                            <tr>
                                <th class="min-width">
                                    <input type="checkbox" class="js-jobs-list-select-all" />
                                </th>
                                <th class="min-width">@Strings.Common_Id</th>
                                <th>@Strings.FailedJobsPage_Table_Failed</th>
                                <th>@Strings.Common_Job</th>
                            </tr>
                        </thead>
                        <tbody>
                            @{ var index = 0; }
                            @foreach (var job in failedJobs)
                            {
                                <tr class="js-jobs-list-row @(!job.Value.InFailedState ? "obsolete-data" : null) @(job.Value.InFailedState ? "hover" : null)">
                                    <td rowspan="@(job.Value.InFailedState ? "2" : "1")">
                                        @if (job.Value.InFailedState)
                                        {
                                            <input type="checkbox" class="js-jobs-list-checkbox" name="jobs[]" value="@job.Key" />
                                        }
                                    </td>
                                    <td class="min-width" rowspan="@(job.Value.InFailedState ? "2" : "1")">
                                        @Html.JobIdLink(job.Key)
                                        @if (!job.Value.InFailedState)
                                        {
                                            <span title="@Strings.Common_JobStateChanged_Text" class="glyphicon glyphicon-question-sign"></span>
                                        }
                                    </td>
                                    <td class="min-width">
                                        @if (job.Value.FailedAt.HasValue)
                                        {
                                            @Html.RelativeTime(job.Value.FailedAt.Value)
                                        }
                                    </td>
                                    <td>
                                        <div class="word-break">
                                            @Html.JobNameLink(job.Key, job.Value.Job)
                                        </div>
                                        @if (!String.IsNullOrEmpty(job.Value.ExceptionMessage))
                                        {
                                            <div style="color: #888;">
                                                @job.Value.Reason <a class="expander" href="#">@(index == 0 ? Strings.Common_LessDetails : Strings.Common_MoreDetails)</a>
                                            </div>
                                        }
                                    </td>
                                </tr>
                                if (job.Value.InFailedState)
                                {
                                    <tr>
                                        <td colspan="2" class="failed-job-details">
                                            <div class="expandable" style="@(index++ == 0 ? "display: block;" : null)">
                                                <h4>@job.Value.ExceptionType</h4>
                                                <p class="text-muted">
                                                    @job.Value.ExceptionMessage
                                                </p>

                                                @if (!String.IsNullOrEmpty(job.Value.ExceptionDetails))
                                                {
                                                    <pre class="stack-trace"><code>@Html.StackTrace(job.Value.ExceptionDetails)</code></pre>
                                                }
                                            </div>
                                        </td>
                                    </tr>
                                }
                            }
                        </tbody>
                    </table>
                </div>

                @Html.Paginator(pager)
            </div>
        }
    </div>
</div>